package com.ruoyi.pg.costSetting.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pg.costSetting.vo.PgChargedItemsVo;
import com.ruoyi.pg.costSetting.service.IPgChargedItemsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 收费项目Controller
 *
 * @author Ming
 * @date 2025-10-20
 */
@Api(tags = "收费项目Controller")
@RestController
@RequestMapping("/pg/chargedItems")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PgChargedItemsController extends BaseController {

    private final IPgChargedItemsService pgChargedItemsService;

    @ApiOperation("查询收费项目列表")
    @GetMapping("/list")
    public TableDataInfo<PgChargedItemsVo> list(PgChargedItemsVo entity) {
        return pgChargedItemsService.queryList(entity);
    }

    @ApiOperation("查询收费项目所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(PgChargedItemsVo entity) {
        return AjaxResult.success("查询成功", pgChargedItemsService.queryAll(entity));
    }

    @ApiOperation("导出收费项目列表")
    @Log(title = "收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PgChargedItemsVo entity) {
        List<PgChargedItemsVo> list = pgChargedItemsService.queryAll(entity);
        ExcelUtil<PgChargedItemsVo> util = new ExcelUtil<>(PgChargedItemsVo.class);
        util.exportExcel(response, list, "收费项目数据");
    }

    @ApiOperation("获取收费项目详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", pgChargedItemsService.queryById(id));
    }

    @ApiOperation("新增收费项目")
    @Log(title = "收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PgChargedItemsVo entity) {
        return toAjax(pgChargedItemsService.save(entity));
    }

    @ApiOperation("修改收费项目")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PgChargedItemsVo entity) {
        return toAjax(pgChargedItemsService.updateById(entity));
    }

    @ApiOperation("删除收费项目")
    @Log(title = "收费项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pgChargedItemsService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
